package cn.xm.result;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

//返回JSON结果
@Data
@NoArgsConstructor
@AllArgsConstructor
//建造者模式
@Builder
public class AjaxResult {

    private boolean success = true;

    private String message = "成功";

    //错误码，用来描述错误类型 ，1000 表示么有错误
    private String code = "1000";

    //返回的数据
    private Object data;

    public static AjaxResult success() {
        return new AjaxResult();
    }

    public static AjaxResult success(Object data) {
        return AjaxResult.builder().data(data).build();
    }

    public static AjaxResult success(String message, Object data) {
        return AjaxResult.builder().data(data).message(message).build();
    }

    public static AjaxResult error(String message) {
        return AjaxResult.builder().message(message).success(false).build();
    }

    public static AjaxResult error(String code, String message) {
        return AjaxResult.builder().code(code).message(message).success(false).build();
    }

    public static AjaxResult error(String code, String message, Object data) {
        return AjaxResult.builder().code(code).message(message).data(data).success(false).build();
    }
}
